import { ref, computed } from "vue";
import { defineStore } from "pinia";
import { listUserRole } from "../service/user";

export const useUserStore = defineStore("user", () => {
    const userId = ref();
    const user = ref({});
    const userRoleVisible = ref(false);
    const allRoles = ref([]);
    const assignRoles = ref([]);
    async function fetchUserRole(id){
        userId.value = id;
        let res = await listUserRole(id);
        allRoles.value = res.data.all.map(item => ({key:item.id,label:item.name}));
        assignRoles.value = res.data.assign.map(item => item.id);
    }
    return {userId,user,userRoleVisible,allRoles,assignRoles,fetchUserRole};
});
